/**
 * 
 */
package com.java.test.platmanage.mapper;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.java.test.platmanage.dto.PlatParamInfo;

/**
 * @author Administrator
 *
 */
@Component
public class PlatParamMapper {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public List<PlatParamInfo> selectplatList() {

		String sql = "select * from plat_param_info order by update_time desc";

		List<PlatParamInfo> list = jdbcTemplate.query(sql, new PlatParamInfo());

		return list;

	}

	public PlatParamInfo selectplatInfoById(int platId) {

		String sql = "select * from plat_param_info where id=?";

		PlatParamInfo info = null;
		try {
			info = jdbcTemplate.queryForObject(sql, new PlatParamInfo(), platId);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return info;

	}

	public boolean selectcheckdomain(String domainName) {

		String sql = "select count(*) from plat_param_info where realm_name=?";

		try {
			int i = jdbcTemplate.queryForObject(sql, Integer.class, domainName);
			if (i > 0) {
				return true;
			} else {
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	public boolean selectplatname(String platName) {

		String sql = "select count(*) from plat_param_info where plat_name=?";

		try {
			int i = jdbcTemplate.queryForObject(sql, Integer.class, platName);
			if (i > 0) {
				return true;
			} else {
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	public int insertplatParam(PlatParamInfo info) {
		String sql = "insert into plat_param_info(plat_name,realm_name,content,update_time,param_list)values(?,?,?,now(),?)";

		int i = jdbcTemplate.update(sql, info.getPlatName(), info.getRealmName(), info.getContent(),info.getParamList());

		return i;
	}

	public int updateplatParam(PlatParamInfo info) {

		String sql = "update plat_param_info set plat_name=?,realm_name=?,"
				+ "content=?,update_time=now(),param_list=? where id  = ?";

		int i = jdbcTemplate.update(sql, info.getPlatName(), info.getRealmName(), info.getContent(),info.getParamList(), info.getId());

		return i;

	}

	/**
	 * @param info
	 * @return
	 */
	public int updateplatparamStatus(PlatParamInfo info) {
		String sql = "update plat_param_info set status=?,update_time=now() where id =?";

		int i = jdbcTemplate.update(sql, info.getStatus(), info.getId());

		return i;
	}

}
